import imgUrl from "../../images/util.js"
import {adapter} from "../../utils/index.js"
let app=getApp()
Page({
  data:{
    isAdapter:false,
    appointmentEmpIcon:imgUrl.appointmentEmpIcon,
    appointmentTimeIcon:imgUrl.appointmentTimeIcon,
    isHours:false,
    isMinute:false,
    selectHoursArr:[0,1,2,3],
    selectMinuteArr:[0,15,20,25],


    minute:0,
    hours:0,

    name:"请选择",

    date:"请选择预约的时间",
 
   
  },

  

  inputHours(e){
    let timeNum= 23*60

    if(( Number(e.detail.value*60) +Number(this.data.minute) )   > timeNum){
       wx.showToast({
         icon:"none",
         title:"服务时长不能超过23小时",
         duration:2500
       })
       this.setData({
        hours:Number(0+"") 
      })
      this.selectComponent("#asyncDate").passTime(this.data.hours,this.data.minute)

    }else{
      this.setData({
        hours:Number(e.detail.value+"") 
      })
      this.selectComponent("#asyncDate").passTime(this.data.hours,this.data.minute)
    }

   
  },
  inputMinute(e){
      let timeNum= 23*60
      if( ( Number(this.data.hours)*60 +Number(e.detail.value) ) < timeNum ){
        if(e.detail.value<=60){
          this.setData({
            minute:Number(e.detail.value+"")
          })
          this.selectComponent("#asyncDate").passTime(this.data.hours,this.data.minute)
        }else{
          this.setData({
            minute:60
          })
          this.selectComponent("#asyncDate").passTime(this.data.hours,this.data.minute)
        }
      }else{
        wx.showToast({
          icon:"none",
          title:"服务时长不能超过23小时",
          duration:2500
        })
        this.setData({
          minute:0
        })
      }

       
   
  },
  selectHours(e){
    this.setData({
      hours:e.currentTarget.dataset.item,
      isHours:false
    })
    this.selectComponent("#asyncDate").passTime(this.data.hours,this.data.minute)
  },
  selectMinute(e){
    this.setData({
      minute:e.currentTarget.dataset.item,
      isMinute:false
    })
    this.selectComponent("#asyncDate").passTime(this.data.hours,this.data.minute)
  },




  openSelectHoursPop(){
    this.setData({
      isHours:!this.data.isHours,
      isMinute:false
    })
  },
  openSelectMinutePop(){
    this.setData({
      isMinute:!this.data.isMinute,
      isHours:false
    })
  },
 
  jumpStaff(){
    wx.navigateTo({
      url: '../staff-management/staff-management?id=1',
    })
  },
  onLoad(){
    setTimeout(()=>{
       
    
    },2000)
  },
  onShow(){
    adapter().then(res=>{
      // console.log(res)
      this.setData({
        isAdapter:res
      })
    })
    this.selectComponent("#asyncDate").passTime(this.data.hours,this.data.minute)
    console.log("嘿嘿", app.globalData.appointEmp)
    // 从员工管理 选择 带过来的数据
    let {birthday,education,employeeId,employeeName,employeePhone,gender} =app.globalData.newAddStaff
    // 保存到预约的 信息 对象中去
    app.globalData.appointEmp={birthday,education,employeeId,employeeName,employeePhone,gender}
    
    this.setData({
      name:employeeName||"请选择"
    })


  },
  getShowText(e){
    console.log("showText", e.detail)
    this.setData({
      date:e.detail||"请选择预约的时间"
    })

  },
  next(){
    let isNext =true

    if(this.data.date =="请选择预约的时间"){
      wx.showToast({
        title: '请选择预约时间',
        icon:"none",
        duration:2000
      })
      isNext=false
     }
     
     if(this.data.hours == 0 & this.data.minute == 0){
      wx.showToast({
        title: '请选择服务时长',
        icon:"none",
        duration:2000
      })
      isNext=false
     }

     if(JSON.stringify(app.globalData.newAddStaff)== "{}"){
       wx.showToast({
         title: '请预约家政师',
         icon:"none",
         duration:2000
       })
       isNext=false
     }
     

     if(isNext){
       
      //  console.log("jump" , this.data.date.split(" ")[1])
      //  this.data.date.split(" ")[1].split("至")[0]
       let timeObj={
         text:this.data.date,
         timeLength:(this.data.hours || 0)+"小时"+(this.data.minute||0)+"分钟",
         startTime:this.data.date.split("至")[0],
         endTime:this.data.date.split("至")[1]
       }

       app.globalData.appointmentTime=timeObj

       wx.navigateTo({
         url: '../submitAppointment/submitAppointment',
       })
     }

  }

 
})